package xyz.lisys.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import xyz.lisys.service.AsyncService;

import java.util.concurrent.Future;

@Service
@Slf4j
public class AsyncServiceImpl implements AsyncService {

    @Async
    public void sleep() throws InterruptedException {
        log.info("---------test1 start: {}", Thread.currentThread().getName());
        Thread.sleep(5000);
        log.info("---------test1 end: {}", Thread.currentThread().getName());
    }

    @Async
    public Future<String> returnValueAfterSleep() throws InterruptedException {
        Thread.sleep(5000);
        return new AsyncResult<>("hello world");
    }
}
